home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group97a.txt
/
000053_icon-group-sender _Fri Feb 28 11:15:31 1997.msg
< prev
next >
Wrap
Internet Message Format
|
2000-09-20
|
2KB
Received: by cheltenham.cs.arizona.edu; Fri, 28 Feb 1997 12:48:10 MST
Date: Fri, 28 Feb 1997 11:15:31 -0600
Message-Id: <199702281715.LAA15028@ns1.cmpu.net>
Mime-Version: 1.0
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
From: gep2@computek.net
Subject: Help with Program
To: icon-group@cs.arizona.edu
X-Mailer: SPRY Mail Version: 04.00.06.17
Errors-To: icon-group-errors@cs.arizona.edu
Status: RO
Content-Length: 1738
>Hello. I am trying to do some text analysis with Icon. Because I am new
to the language (and to programming in general), I am not sure how to
proceed.
>I have a number of texts each line of which has been coded for three types
of information. Each line of the text will be assigned a number and a
code for two categories. The numbers are just whole numbers (raning from 1
to 20 or so) and each category has four members (say, ABCD and WXYZ).
Here is an example text:
>1 A X
1 A Y
1 B Y
2 B Y
>Note that some successive lines share an index number (as in lines 1 and
2 and 2 and 3). When that is the case, I would like the program to
output the members of each category for the matched lines, as below:
>1-2 AA XY
2-3 AB YY
>Any suggestions? Thanks in advance.
Took me a while to understand what you wanted, but here at least would be a
SNOBOL4+/SPITBOL version of a complete program that does what you want:
SWS = SPAN(" " CHAR(9)) ;* 'span whitespace' pattern
TAB = CHAR(9) ;* define a tab character
LET = ANY(&LCASE &UCASE) ;* parse an alpha character
RECPAT = SPAN("0123456789") . N SWS LET . M1 SWS LET . M2
RLOOP (?(N1 = N) ?(M1A = M1) ?(M2A = M2) ?(LN1 = LN)) ;* remember prior line
LINE = INPUT ?(LN = LN + 1) :F(END) ;* read and count line
OUTPUT = ~(LINE ? RECPAT) "Line number " LN " is invalid." :S(RLOOP)
OUTPUT = EQ(N1,N) LN1 "-" LN TAB M1A M1 TAB M2A M2 :(RLOOP)
END
The short length and speed of doing stuff like this in SNOBOL4+/SPITBOL is part
of what still incites me to do this kind of thing in S-BOL rather than Icon...
I'll be interested to see what kinds of Icon versions people post!
Gordon Peterson
http://www.computek.net/public/gep2/